﻿
using MqLibrary;
using RabbitMqService;
using RabbitMqService.Worker;
using RabbitMqService.Workers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AvatarWeb.Controllers
{
    public class TestSendController : Controller
    {
        static WorkerManager _workerManager = WorkerManager.Instance;
        static SendMailWorker _sendMailWorker = new SendMailWorker();
        static SendSMSWorker _sendSMSWorker = new SendSMSWorker();

        // GET: /TestSend/



        public ActionResult Index()
        {
            return View();
        }

        //发送邮件
        public ActionResult StartMail()
        {
            ViewBag.Result = _workerManager.StartWork(_sendMailWorker);
            return View("start");
        }
        //关闭邮件
        public ActionResult StopMail()
        {
            ViewBag.Result = _workerManager.StopWork(_sendMailWorker);
            return View("stop");
        }

        public ActionResult StartSms()
        {
            ViewBag.Result = _workerManager.StartWork(_sendSMSWorker);
            return View("start");
        }
        public ActionResult StopSms()
        {
            ViewBag.Result = _workerManager.StopWork(_sendSMSWorker);
            return View("stop");
        }
        public ActionResult TestLog()
        {
            Log.WriteMailInfo("Mail");
            Log.WriteSMSlInfo("SMS");
            return View("index");
        }

        public ActionResult Delete()
        {
            int i = 0;
            int n = 0;
            while(true)
            {
                
                RabbitHelper<EmailModel> cs = new RabbitHelper<EmailModel>();
                EmailModel result = cs.GetRabbitMq(RabbitTypeEnum.Email);
                if (result == null) break;
                i++;
                DebugWriter.Writer(i.ToString());
            }   
            while(true)
            {
                RabbitHelper<ShortMessageModel> cs = new RabbitHelper<ShortMessageModel>();
                ShortMessageModel result = cs.GetRabbitMq(RabbitTypeEnum.Message);
                if (result == null) break;
                n++;
                DebugWriter.Writer(n.ToString());

            } 
            return View("index");
        }
    }
}
